package utils
{

	import flash.net.ObjectEncoding;
	import flash.net.SharedObject;

	public class ShareUtils
	{
		private var lso:SharedObject;

		private static var instance:ShareUtils;

		public static function getInstance():ShareUtils
		{
			if (instance == null)
			{
				instance=new ShareUtils();
			}
			return instance;
		}

		public function ShareUtils()
		{
			lso=SharedObject.getLocal("sunny_boxs");
			lso.objectEncoding=ObjectEncoding.AMF3;
		}

		public function get(property:String):*
		{
			var o:*=lso.data[property];
			if (o == undefined || o == "undefined")
			{
				o=null;
			}
			return o;
		}

		public function save(property:String, data:*):Boolean
		{
			try
			{
				lso.setProperty(property, data);
				flush();
			}
			catch (e:Error)
			{
			}
			return true;
		}

		public function clear(property:String):Boolean
		{
			try
			{
				lso.data[property]=null;
				delete lso.data[property];
				flush();
			}
			catch (e:Error)
			{
			}
			return true;
		}

		public function flush():void
		{
			try
			{
				lso.flush(0);
			}
			catch (e:Error)
			{
			}
		}

		public function clearAll():void
		{
			lso.clear();
		}
	}
}
